<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Globestore  extends CI_Controller {

  public function index()
  {   
     //welcome page
     $d['hello'] ="data";    
     $views['_content'] = "globestore";
     $this->template->load('template_landing', $views, $d);
	 
	 $this->load->model('transaction');	 

	 $fName = $this->input->post("Fname"); 
	 $mName = $this->input->post("Mname");
	 $lName = $this->input->post("Lname");
	 $nName = $this->input->post("Nname");
	 $email = $this->input->post("Eadd");
	 if(isset($_COOKIE['fb_mobtel'])) $msisdn = $_COOKIE['fb_mobtel'];
	 $otherCont = $this->input->post("Othercont");
	 date_default_timezone_set('Asia/Manila');
	 $birthdate = date("Y-m-d",strtotime($this->input->post("birthday")));
	 $street = $this->input->post("Address");
	 if(isset($_COOKIE['fb_area'])) $area = $_COOKIE['fb_area'];
	 if(isset($_COOKIE['fb_town'])) $town = $_COOKIE['fb_town'];
	 if(isset($_COOKIE['fb_province'])) $province = $_COOKIE['fb_province'];
	 if(isset($_COOKIE['fb_postalcode'])) $postalCode = $_COOKIE['fb_postalcode'];
	 if(isset($_COOKIE['fb_gadgetid'])) $gadgetId = $_COOKIE['fb_gadgetid'];
	 if(isset($_COOKIE['fb_promoid'])) $promoId = $_COOKIE['fb_promoid'];
	 
	 if($fName!="")
	 $this->transaction->saveUserProfileToDB($fName, $mName, $lName, $nName, $email, $msisdn, $otherCont, $birthdate, $street, $area, $town, $province, $postalCode, $gadgetId, $promoId);

  }
  
  public function storelocator(){
      /* call this when getting map of client address */ 
      if( isset($_POST["isAjax"]) ){  
        $area = trim($_POST["area"]); $brgy= trim($_POST["brgy"]); $city= trim($_POST["city"]); $town= trim($_POST["town"]); $locator = $_POST["locator"]; $region = $_POST["region"];        
        //$area = ""; $brgy = "Bagong Pagasa"; $city = "Quezon City"; $town = " ";$locator ="nearest"; $region ="visayas"; //[Debug]
        
        $s = json_encode($this->storelocator->locateStore($city,$town,$brgy,$area,$locator,$region)); // stripslashes kasi may slashes - given n lahat ng params sa locateStore
        echo $s;  
        return true; 
        } // if not ajax call
       echo "Forbidden Access";  
  }   
  public function getStoresFromDB(){
    $this->load->model('store');    
    $stores = $this->store->getStoreFromDB();
    print_r($stores);
    die();  
  }    
  
}
 